package com.boot.study.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dangdang.ddframe.rdb.sharding.api.HintManager;

@Service
@ConditionalOnProperty(prefix = "master-slave", name="open", havingValue ="true")
public class MasterSevice {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Transactional
	public void hint() {
		HintManager hintManager = HintManager.getInstance();
		hintManager.setMasterRouteOnly();
		List<Map<String, Object>> list = jdbcTemplate.queryForList("select * from t_user");
		System.out.println(list);

		// update
		// insert
		// delete

		list = jdbcTemplate.queryForList("select * from t_user");
		System.out.println(list);
	}
}
